package com.algorithm.thePrimaryAlgorithm;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

@Slf4j
public class ArraySulotionLC05 {
    /**
     * a^a=0；自己和自己异或等于0
     *
     * a^0=a；任何数字和0异或还等于他自己
     *
     * a^b^c=a^c^b；异或运算具有交换律
     * @param nums
     * @return
     */
    public int singleNumber(int[] nums) {
       int result = 0;
        for (int i = 0; i < nums.length; i++) {
            result ^= nums[i];
        }

        return result;
    }

    @Test
    public void test(){
        int [] nums = {4,1,2,1,2};
        int i = singleNumber(nums);
        log.info("sdsd {}",i);
    }
}
